import request from '@/utils/request'
import { encryptedData } from '@/utils/encrypt'
import { loginRSA } from '@/config'

export async function login(data) {
  if (loginRSA) {
    data = await encryptedData(data)
  }
  return request({
    url: '/user/login',
    method: 'post',
    data,
  })
}

export async function socialLogin(data) {
  if (loginRSA) {
    data = await encryptedData(data)
  }
  return request({
    url: '/socialLogin',
    method: 'post',
    data,
  })
}

export function userInfo(data) {
  return request({
    url: '/user/index',
    method: 'post',
    data,
  })
}

export function logout(data) {
  return request({
    url: 'user/logout',
    method: 'post',
    data,
  })
}

export function resetpwd(data) {
  return request({
    url: '/user/resetpwd',
    method: 'post',
    data,
  })
}

export function register(data) {
  return request({
    url: '/user/register',
    method: 'post',
    data,
  })
}

export function addTrust(data) {
  return request({
    url: 'user/add_trust',
    method: 'post',
    data,
  })
}

export function importPhoto(data) {
  return request({
    url: 'import/import_photo',
    method: 'post',
    headers: { 'Content-Type': 'multipart/form-data' },
    data,
  })
}
// 邮箱验证码
export function checkEmail(data) {
  return request({
    url: 'ems/send',
    method: 'post',
    data,
  })
}
// 确认认证
export function checkAdd(data) {
  return request({
    url: 'import/user_vaild',
    method: 'post',
    data,
  })
}
// 手机获取验证码
export function getCaptcha(data) {
  return request({
    url: 'sms/send',
    method: 'post',
    data,
  })
}
// 确认修改密码
export function changePsd(data) {
  return request({
    url: 'user/change_pwd',
    method: 'post',
    data,
  })
}
// 确认修改手机号
export function changePhone(data) {
  return request({
    url: 'user/change_mobile',
    method: 'post',
    data,
  })
}
// 确认修改支付密码
export function changePaypwd(data) {
  return request({
    url: 'user/change_pay_pwd',
    method: 'post',
    data,
  })
}
